import java.util.Scanner;

public class TestDemo {
    public static int Func(int num) {
        if(num==1) {
            return 1;
        }else {
            int sum = num * Func(num-1);
            return sum;
        }
    }
    //递归求 N 的阶乘
    public static void main(String[] args) {
        System.out.println("请输入你要求几的阶乘");
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(Func(n));
    }


    public static int Sum(int num) {
        if (num == 1) {
            return 1;
        } else {
            int ret = num + Sum(num - 1);
            return ret;
        }
    }
    //递归求 1 + 2 + 3 + ... + 10
    public static void main4(String[] args) {
        int n = 10;
        System.out.println(Sum(n));
    }


    //写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static int print2(int num) {//124
        if(num<10) {
            return num;
        }else {
            int sum =0;
            //4+2+1
            sum += num % 10 + print2(num/10);
            return sum;
        }
    }


    public static int fib(int num) {
        if(num==1||num==2) {
            return 1;
        }else {
            int ret  = fib(num-1)+fib(num-2);
            return ret;
        }
    }
//递归求斐波那契数列的第 N 项
public static void main3(String[] args) {
    System.out.println("请输入你要求第几项斐波那契数");
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    System.out.println(fib(n));
}



//按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4) （递归）
    public static void print(int num) {
        if(num<10) {
            System.out.println(num);
        }else {
            print(num/10);
            System.out.println(num % 10);
        }
    }
public static void main2(String[] args) {
    System.out.println("请输入一个非负整数");
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
   // print(n);
    System.out.println(print2(n));
}


    public static void main1(String[] args) {
        //求斐波那契数列的第n项。(迭代实现)
        System.out.println("请输入你想求第几项斐波那契数");
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        if(n==1||n==2) {
            System.out.println("1");
        }else {
             int f1 = 1;
             int f2 = 1;
             int f3 = -1;
            for (int i = 3; i <= n; i++) {
                f3 = f1 + f2;
                f1 = f2;
                f2 = f3;
            }
            System.out.println(f3);
        }
    }
}
